package com.hlhj.carview.utils

import android.content.Context

/**
 * Created by Never Fear   on 2019\1\4 0004.
Never More....
 */
object SPHelper {
    private val TOKEN="token"
    private val LOGIN="login"
    private val HEAD="head"
    fun saveLogin(isLogin:Boolean,c:Context){
        val sp = c.getSharedPreferences(LOGIN, Context.MODE_PRIVATE)
        val edit = sp.edit()
        edit.putBoolean("islogin",isLogin)
        edit.apply()
    }
    fun getLogin(c:Context): Boolean {
        val sp = c.getSharedPreferences(LOGIN, Context.MODE_PRIVATE)
        return sp.getBoolean("islogin",false)
    }
    fun saveToken(token:String,c:Context){
        val sp = c.getSharedPreferences(TOKEN, Context.MODE_PRIVATE)
        val edit = sp.edit()
        edit.putString("token",token)
        edit.apply()
    }

    fun getToken(c:Context): String? {
       return c.getSharedPreferences(TOKEN,Context.MODE_PRIVATE).getString("token",null)
    }

    fun saveHead(head:String,c:Context){
        val sp = c.getSharedPreferences(HEAD, Context.MODE_PRIVATE)
        val edit = sp.edit()
        edit.putString("head",head)
        edit.apply()
    }

    fun getHead(c:Context): String? {
        return c.getSharedPreferences(HEAD,Context.MODE_PRIVATE).getString("head",null)
    }

    fun getFirst(c:Context): Boolean {
        return c.getSharedPreferences(HEAD,Context.MODE_PRIVATE).getBoolean("first",true)

    }

    fun saveFirst(b:Boolean,c:Context){
        val sp = c.getSharedPreferences(HEAD, Context.MODE_PRIVATE)
        val edit = sp.edit()
        edit.putBoolean("first",b)
        edit.apply()
    }
}